/**
 ******************************************************************************
 * @file    wdog.h
 * @author  hyseim software Team
 * @date    27-Mar-2024
 * @brief   This file provides all the headers of the wdog functions.
 ******************************************************************************
 * @attention
 *
 * Copyright (c) 2020 Hyseim. Co., Ltd.
 * All rights reserved.
 *
 * This software is licensed under terms that can be found in the LICENSE file
 * in the root directory of this software component.
 * If no LICENSE file comes with this software, it is provided AS-IS.
 *
 ******************************************************************************
 */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __WDOG_H__
#define __WDOG_H__

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "chip_define.h"
#include "utils.h"

/* ================================================================================ */
/* ================                 Watchdog (WDOG)                ================ */
/* ================================================================================ */
typedef struct
{
    __IO uint32_t WDOGLOAD;             /*!< Count Value Loading Register,               Address offset: 0x000 */
    __I  uint32_t WDOGVALUE;            /*!< Current Counter Value Register,             Address offset: 0x004 */
    __IO uint32_t WDOGCONTROL;          /*!< Watchdog Control Register,                  Address offset: 0x008 */
    __O  uint32_t WDOGINTCLR;           /*!< Clear Interrupt register,                   Address offset: 0x00C */
    __I  uint32_t WDOGRIS;              /*!< Raw Interrupt Status register,              Address offset: 0x010 */
    __I  uint32_t WDOGMIS;              /*!< Interrupt Status register,                  Address offset: 0x014 */
         uint32_t RESERVED0[762];
    __IO uint32_t WDOGLOCK;             /*!< Watchdog Lock register,                     Address offset: 0xC00 */
         uint32_t RESERVED1[63];
    __IO uint32_t WDOGWINVAL;           /*!< Window Value register,                      Address offset: 0xD00 */
         uint32_t RESERVED2[127];
    __IO uint32_t WDOGITCR;             /*!< Integration Test Control Register,          Address offset: 0xF00 */
    __O  uint32_t WDOGITOP;             /*!< Integration Test Output Set register,       Address offset: 0xF04 */
} WDOG_t;

#define WDOG                            ((WDOG_t *) WDOG_BASE)
/* ================================================================================ */
/* ================                 Watchdog (WDOG)                ================ */
/* ================================================================================ */
/********************************  Bit definition for WDOG_CONTROL register  ********************************/
#define WDOG_CONTROL_INT_EN              (0x1U << 0)           /*!< Enable WDOG and interrupt */
#define WDOG_CONTROL_RESET_EN            (0x1U << 1)           /*!< WDOG reset enable */
#define WDOG_CONTROL_WINDOW_MODE         (0x1U << 2)           /*!< WDOG window mode enable */
#define WDOG_CONTROL_DEBUG_MODE          (0x1U << 3)           /*!< WDOG debug mode enable */

/********************************  Bit definition for WDOG_MIS register  ********************************/
#define WDOG_MIS_INT_STATUS_MASK         (0x1U << 0)           /*!< Interrupt status */

/********************************  Bit definition for WDOG_LOCK register  ********************************/
#define WDOG_LOCK_ENABLE                 (0x1U << 0)           /*!< Write register lock enable */
#define WDOG_UNLOCK_KEY                  (0xA6C2F4EB)          /*!< Unlocked Key */

/** @addtogroup IM110GW_WDOG_Driver
  * @{
  */

/** @addtogroup WDOG
  * @{
  */

/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/

/** @defgroup WDOG_Exported_Constants
  * @{
  */

/** @defgroup WDOG_TestMode_Enable
  * @{
  */
#define WDOG_TestMode_Enable                (0x1U << 0)
#define WDOG_TestMode_Disable               (0x0U << 0)
/**
  * @}
  */


/** @defgroup WDOG_TestMode_Reset_Value
  * @{
  */
#define WDOG_TestMode_Reset_Enable          (0x1U << 0)
#define WDOG_TestMode_Reset_Disable         (0x0U << 0)
/**
  * @}
  */


/** @defgroup WDOG_TestMode_Interrupt_Value
  * @{
  */
#define WDOG_TestMode_Interrupt_Enable      (0x1U << 1)
#define WDOG_TestMode_Interrupt_Disable     (0x0U << 1)
/**
  * @}
  */

/**
  * @}
  */

/* Exported macro ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/

void WDOG_Enable(void);
void WDOG_Disable(void);
void WDOG_SetResetMode(void);
void WDOG_SetWindowMode(void);
void WDOG_SetDebugMode(void);
void WDOG_Lock(void);
void WDOG_Unlock(void);
void WDOG_SetWindowValue(uint32_t WindowValue);
void WDOG_SetLoadValue(uint32_t LoadValue);
uint32_t WDOG_GetCounterValue(void);
FlagStatus_t WDOG_GetITStatus(void);
void WDOG_ClearITFlag(void);
void WDOG_ConfigTestMode(uint8_t TestMode_En);
void WDOG_SetTestMode_Status(uint8_t TestINTValue, uint8_t TestResetValue);

/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

#endif
